package com.crx.springbootinit.service.impl;

import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crx.springbootinit.mapper.LogApiMapper;
import com.crx.springbootinit.model.dto.logApi.LogApiPageDTO;
import com.crx.springbootinit.model.dto.page.PageVO;
import com.crx.springbootinit.model.entity.LogApi;
import com.crx.springbootinit.model.vo.logApi.LogApiPageVO;
import com.crx.springbootinit.service.ILogApiService;
import org.springframework.stereotype.Service;

/**
 * @author 谢杭延
 * @Date 2024-10-28 20:22
 */
@Service
public class LogApiServiceImpl extends ServiceImpl<LogApiMapper, LogApi> implements ILogApiService {
    @Override
    public PageVO<LogApiPageVO> queryLogApiPage(LogApiPageDTO logApiPageDTO) {
        Integer pageNo = logApiPageDTO.getPageNo();
        Integer pageSize = logApiPageDTO.getPageSize();
        String requestType = logApiPageDTO.getRequestType();
        Page<LogApi> logApiPage = new Page<>(pageNo, pageSize);
        Page<LogApi> page = lambdaQuery().eq(StringUtils.isNotBlank(requestType), LogApi::getRequestType, requestType)
                .orderByDesc(LogApi::getOperationTime)
                .page(logApiPage);
        return PageVO.of(page, LogApiPageVO.class);
    }
}
